package com.yl.auth.utils;

import com.yl.auth.model.entity.Yuangong;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * @author 郭家正
 * @datetime 2023/7/20 16:54
 * @description 类对象
 */

public class TokenUtil {
    private static Map<String, Yuangong> tokenMap = new HashMap<>();
    public static String generateToken(Yuangong yuangong){
        //生成唯一不重复的字符串
        String token = UUID.randomUUID().toString();
        tokenMap.put(token,yuangong);
        return token;
    }

    /**
     * 验证token是否合法
     * @param token
     * @return
     */
    public static  boolean verify(String token){
        return tokenMap.containsKey(token);
    }

    public static Yuangong gentUser(String token){
        return tokenMap.get(token);
    }

    public static void main(String[] args) {
        for (int i = 0; i < 20; i++){
            System.out.println(UUID.randomUUID().toString());
        }
    }
}
